<?php

namespace catchAdmin\transport\controller;

use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catchAdmin\transport\model\Transport as TransportModel;
use think\Response;
use catcher\CatchAuth;

use catchAdmin\permissions\model\Users;

class Transport extends CatchController
{
    
    protected $transportModel;
    
    /**
     *
     * @time 2022/02/21 10:20
     * @param TransportModel $transportModel
     * @return mixed
     */
    public function __construct(TransportModel $transportModel)
    {
        $this->transportModel = $transportModel;
    }
    
    /**
     * 列表和搜索
     * @time 2022/02/21 10:20
     * @return Response
     */
    public function index(CatchAuth $auth) : Response
    {
        $user = $auth->user();
        return CatchResponse::paginate($this->transportModel->getList($user['tenant_id']));
    }

    /**
     * 新建
     * @time 2022/02/15 11:41
     * @throws \think\db\exception\DbException
     * @return \think\response\Json
     */
    public function create(CatchAuth $auth,Request $request)
    {
        $params = $request->filterEmptyField()->post();
        $user = $auth->user();
        $params['tenant_id'] = $user['tenant_id'];
        return CatchResponse::success($this->transportModel->storeBy($params), '新建成功');
    }
    
    /**
     * 更新
     * @time 2022/02/21 10:20
     * @param $id
     * @param Request $request
     * @return Response
     */
    public function update(Request $request) : Response
    {
        $params = $request->filterEmptyField()->post();
        return CatchResponse::success($this->transportModel->updateBy($params['id'], $params),'编辑成功');
    }
    
    /**
     * 删除
     * @time 2022/02/21 10:20
     * @param $id
     * @return Response
     */
    public function delete(Request $request) : Response
    {
        $id = $request->filterEmptyField()->post('id');
        return CatchResponse::success($this->transportModel->deleteBy($id),'删除成功');
    }
}